package com.ydpl.db.eshop.auth.controller;


import com.ydpl.db.eshop.auth.domain.PriorityDTO;
import com.ydpl.db.eshop.auth.domain.PriorityVO;
import com.ydpl.db.eshop.auth.service.PriorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * 权限管理模块的controller组件
 *
 * @author zhonghuashishan
 */
@RestController
@RequestMapping("/auth")
public class PriorityController {

    /**
     * 权限管理模块的service组件
     */
    @Autowired
    private PriorityService priorityService;

    /**
     * 查询根权限
     *
     * @return 根权限集合
     */
    @GetMapping("/priority/root")
    public List<PriorityVO> listRootPriorities() {

        List<PriorityDTO> priorityDTOS = priorityService.listRootPriorities();

        ArrayList<PriorityVO> priorityVOS = new ArrayList<>(priorityDTOS.size());
        for (PriorityDTO priorityDTO : priorityDTOS) {
            priorityVOS.add(priorityDTO.clone(PriorityVO.class));
        }
        return priorityVOS;
    }

}
